import {
  Controller,
  Get,
  Post,
  Query,
  UseInterceptors,
  UploadedFile,
} from '@nestjs/common';
import { PictureService } from './picture.service';
import { PaginationDto } from 'src/common/dto/pagination.dto';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { FileInterceptor } from '@nestjs/platform-express';
import { Express } from 'express';
import { PictureListResponseVo, PictureVo } from './vo/picture.vo';

@ApiTags('图床模块')
@Controller('picture')
export class PictureController {
  constructor(private readonly pictureService: PictureService) {}

  @ApiOkResponse({ description: '上传图片', type: PictureVo })
  @Post('upload')
  @UseInterceptors(FileInterceptor('file'))
  upload(@UploadedFile() file: Express.Multer.File) {
    console.log('🚀 ~ PictureController ~ upload ~ file:', file);
    return this.pictureService.upload(file);
  }

  @ApiOkResponse({ description: '获取所有图片', type: PictureListResponseVo })
  @Get()
  findAll(@Query() paginationDto: PaginationDto) {
    return this.pictureService.findAll(paginationDto);
  }
}
